package media.opensync;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class TheOpenSyncActivity extends Activity {
    private EditText ed;
    private EditText edIp;
    private EditText pass;
    public static String serverIp;
    public static String path;
    public static String password;
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        edIp = (EditText)findViewById(R.id.editIp);
        pass = (EditText)findViewById(R.id.pass);
        ed = (EditText)findViewById(R.id.editText1);
        ed.setText("");
        path = "";
        Button b1 = new Button(this);
        b1 = (Button)findViewById(R.id.button1);
        b1.setOnClickListener(new OnClickListener() {
	         public void onClick(View v) {
	        	 //getting password:
	        	 password = pass.getText().toString();
	        	 //getting IP:
	        	 serverIp = edIp.getText().toString();
	        	 //no IP entered:
	        	 if(serverIp.equals("") == true) 
	        		 Toast.makeText(TheOpenSyncActivity.this, "Please enter the ServerIp first!", Toast.LENGTH_SHORT).show();
	        	 //IP entered
	        	 //Check path provided:
	        	 else{
		        		 DirList.SERVERIP = edIp.getText().toString();
		        	 path = ed.getText().toString();
		        	 if(path.equals("")) path = "/";
		        	 Intent myIntent = new Intent(TheOpenSyncActivity.this, DirList.class);
		        	 TheOpenSyncActivity.this.finish();
		        	 startActivity(myIntent);
	        	 }
	         }
        });
        
        Button del = new Button(this);
        del = (Button)findViewById(R.id.button2);
        del.setOnClickListener(new OnClickListener() {
	         public void onClick(View v) {
	        	 path = "";
	        	 ed.setText("");
	         }
        });
        
        Button exit = new Button(this);
        exit = (Button)findViewById(R.id.button3);
        exit.setOnClickListener(new OnClickListener() {
	         public void onClick(View v) {
	        	 TheOpenSyncActivity.this.finish();
	         }
        });
   }
}